Skip to content

sockets: skip NULL ifa_addr entries in get_interfaces instead of stopping #56

Open
a-rank wants to merge 1 commit into
masterfrom
fix/null-ifa-addr
Open

sockets: skip NULL ifa_addr entries in get_interfaces instead of stopping #56
a-rank wants to merge 1 commit into
masterfrom
fix/null-ifa-addr

Conversation

@a-rank

@a-rank a-rank commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

getifaddrs may return entries with ifa_addr==NULL, for example a MAC-less TUN like tailscale0 or wireguard. The loop used ifa->ifa_addr as its continuation condition, so enumeration stopped at the first such entry returning an empty list.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in the Unix implementation of rpp::ipinterface::get_interfaces where network interface enumeration would stop prematurely. The previous code used ifa->ifa_addr as part of the for loop continuation condition, meaning that as soon as getifaddrs returned an entry with ifa_addr == NULL (common for MAC-less TUN interfaces such as tailscale0 or wireguard), the loop terminated. This could result in an empty interface list. Since get_interfaces is a public API that also feeds get_ip_interface, get_system_ip, and get_broadcast_ip, this fix improves reliability of interface discovery on Linux/Unix systems that use such interfaces.

Changes:

  • Moved the ifa->ifa_addr NULL check out of the loop-continuation condition and into the loop body in both the counting and populating loops, so NULL entries are skipped instead of stopping enumeration.
  • Kept the counting loop and populating loop guards identical, ensuring the reserved capacity matches the number of emitted interfaces.
  • Removed a trailing blank line at the end of the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants